var teacherNum = 1
function addTeacher() {
    teacherNum++
    var teachers = $('#validationDefault03').html()
    let tem = `
        <div class="form-row">
        <div class="col-md-6 mb-3">
            <label>出题教师 ${teacherNum} </label>
            <select class="custom-select tbExamWorks">${teachers}</select>
        </div>
        <div class="col-md-3 mb-3">
            <label for="validationDefault04">分配题目</label>
            <select class="custom-select chutishuliang" id="validationDefault04" required>
                <option selected disabled value="0">选择出题数量</option>
                <option value="5">5</option>
                <option value="10">10</option>
                <option value="20">20</option>
                <option value="30">30</option>
                <option value="40">40</option>
                <option value="50">50</option>
            </select>
        </div>
        <div class="col-md-3 mb-3">
            <label for="validationDefault05">备注</label>
            <input type="text" class="form-control beizhu" id="validationDefault05">
        </div>
        
    `
    $('#teacherCon').append(tem);
}

function launch() {
    var endTime = $('#endTime').val()
    endTime = endTime.replace('T',' ')
    var startTime = $('#startTime').val()
    startTime = startTime.replace('T',' ')
    var subject = $('#subject').val()
    var test_amount = $('#test_amount').val()
    var test_name = $('#test_name').val()
    var tbExamWorks = new Array();

    var ADDtest_amount = 0*1
    var teachersLength = $(".tbExamWorks").length
    for (let i = 0; i < teachersLength; i++) {
        console.log($('.tbExamWorks')[i].value)
        console.log($('.chutishuliang')[i].value*1)
        console.log($('.beizhu')[i].value)
        ADDtest_amount += ($('.chutishuliang')[i].value*1)
        let tea = {
            endTime: endTime,
            note: $('.beizhu')[i].value,
            startTime: startTime,
            teacherId: $('.tbExamWorks')[i].value,
            workProblemData: $('.chutishuliang')[i].value
        }
        tbExamWorks.push(tea)
        $("#test_amount").val(ADDtest_amount);
    }

    console.log(tbExamWorks)


    $.ajax({
        type: "POST",
        url: "/admin/createExam/buildTest",
        //---------------------------------------------
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        data: JSON.stringify({
            tbExamWorks: tbExamWorks,
            tbTestWord: {
                subject: subject,
                testAmount: ADDtest_amount,
                testName: test_name
            }
        }),
        success: function (data) {
            console.log(data)
            if (data.err == 0) {
                alert(data.msg);
                window.location.href = "/admin/pages"
            } else {
                alert(data.msg);
            }
        }
    });
}
